package net.lesscoding.shop.utils;

import java.math.BigDecimal;

/**
 * @author eleven
 * @date 2024/6/7 17:38
 * @apiNote
 */
public class BigDecimalUtil {
    public static boolean equals(BigDecimal firstNum, BigDecimal secondsNum) {
        if (firstNum == null || secondsNum == null) {
            return false;
        }
        return firstNum.compareTo(secondsNum) == 0;
    }

    public static boolean moreThan(BigDecimal firstNum, Number secondsNum) {
        return moreThan(firstNum, BigDecimal.valueOf(secondsNum.doubleValue()));
    }

    public static boolean moreThan(BigDecimal firstNum, BigDecimal secondsNum) {
        if (firstNum == null || secondsNum == null) {
            return false;
        }
        return firstNum.compareTo(secondsNum) == 1;
    }

    public static boolean lessThan(BigDecimal firstNum, BigDecimal secondsNum) {
        if (firstNum == null || secondsNum == null) {
            return false;
        }
        return firstNum.compareTo(secondsNum) == -1;
    }

    public static boolean lessThan(Number firstNum, Number secondsNum) {
        return lessThan(BigDecimal.valueOf(firstNum.doubleValue()),
                BigDecimal.valueOf(secondsNum.doubleValue()));
    }

    public static boolean lessOrEquals(BigDecimal firstNum, BigDecimal secondsNum) {
        return lessThan(firstNum, secondsNum) ||
                equals(firstNum, secondsNum);
    }

    public static void main(String[] args) {
        System.out.println(equals(new BigDecimal(0.1), new BigDecimal(0.10)));
        System.out.println(moreThan(new BigDecimal(0.3), new BigDecimal(0.2)));
        System.out.println(lessThan(new BigDecimal(0.1), new BigDecimal(0.2)));
    }
}
